﻿/// <reference path="../GeneratedArtifacts/viewModel.js" />

myapp.Md22CustomPropertiesAddEdit.Delete_execute = function (screen) {
    screen.tlCustomProperty.deleteEntity();
    return myapp.commitChanges().then(null, function fail(e) {
        myapp.cancelChanges();
        throw e;
    });
};

myapp.Md22CustomPropertiesAddEdit.created = function (screen) {
    // Delete Button
    if (screen.tlCustomProperty.IsBoundStatically) {
        var deleteButton = screen.findContentItem('deleteButton');
        deleteButton.isEnabled = (!screen.tlCustomProperty.IsBoundStatically);
    }

    // Choices Tab
    var choicesTabButton = screen.findContentItem('ShowchoicesTab');
    choicesTabButton.isVisible = screen.tlCustomProperty.IsChooseable;
    
    if (screen.tlCustomProperty.IsBoundStatically) {
        var choicesCheckbox = screen.findContentItem('IsChooseable');
        choicesCheckbox.isEnabled = false;
    }

    screen.tlCustomProperty.addChangeListener('IsChooseable', function (e) {
        var contentItem = screen.findContentItem("ShowchoicesTab");
        contentItem.isVisible = screen.tlCustomProperty.IsChooseable;
    });
};
